<?php
namespace App\Http\Controllers\Wx;

use Illuminate\Http\Request;
use App\Http\Controllers\Controller;
use App\Repos\ProductRepo;
use App\Models\Cate;


class ProductController extends Controller
{
    /**
     * Display a listing of the resource.
     *
     * @return \Illuminate\Http\Response
     */
    public function index(Request $request)
    {
        $rs['status']     = true;
        $where['status']  = 1;        
        if($request->cate_id) {
            $where['cate_id'] = (int)$request->cate_id;
        }
        
        $list = ProductRepo::getListPages($where);         
        $rs['data'] = $list;        
        return response()->json($rs);

    }


    public function search(Request $request)
    {
        $rs['status']     = true;
       
        $where['status']  = 1;        
        if($request->keyword) {           
            $where['name'] = trim($request->keyword);
        }       
        $list = ProductRepo::getListPages($where);         
        $rs['data'] = $list;        
        return response()->json($rs);
    }



    public function info(Request $request)
    {
        $rs['status']     = true;
        $where['status']  = 1;        
        $where['id']      = (int)$request->id;          

        $data          = ProductRepo::find($where);
        $data['specs'] = ProductRepo::getSpecs($where['id'],$data->type_id); 
        $data['imgs']  = ProductRepo::imgs($where['id']);     
        $rs['data'] = $data;
        
        return response()->json($rs);
    }

    public function cate(Request $request)
    {
        $rs['status']  = true;
        $where         = [];   
           

        $list = Cate::where($where)->get();
       
        $rs['data'] = $list;
        
        return response()->json($rs);
    }

    public function orderLog(Request $request)
    {
        $rs['status']  = true;
        $list = ProductRepo::orderLog($request->product_id);
        $rs['data'] = $list;
        
        return response()->json($rs);
    }

   

   

    
}
